//
//  ZTLoadZYHTMLViewController+Swap.m
//  ZTSDKDemo
//
//  Created by 武得亮 on 2021/3/17.
//

#import "ZTLoadZYHTMLViewController+Swap.h"

#import "WKWebViewController.h"
#import "ZTLoadZYHTMLViewController.h"
//#import "ZTWebViewController.h"
#import "ZTHttpUrlDefine.h"
#import "ZTMacros.h"
#import "UIViewController+ZTHUD.h"
#import "ZLoadHTMLViewController.h"
#import "ZTUserInfoManage.h"
@implementation ZTLoadZYHTMLViewController (Swap)

#pragma mark- ------ 纯网址跳转 不 需要单点登录 ------
- (void)openSingleH5MethodsWithurlString:(NSString *)urlstring{
    
    if ([urlstring containsString:@"wps"]) {
        WKWebViewController * web = [[WKWebViewController alloc] init];
        web.type = @"2";
        web.titleString = @"协同文档";
        NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:APPDeviceToken];
        if (![urlstring containsString:@"token="]) {
            NSString *urlStr = @"";
            if (![urlstring containsString:@"?"]) {
                urlStr = [NSString stringWithFormat:@"%@?token=%@",urlstring,token];
            }else{
                urlStr = [NSString stringWithFormat:@"%@&token=%@",urlstring,token];
            }
            urlstring = urlStr;
        }
        [web loadWebURLSring:urlstring];
        [self.navigationController pushViewController:web animated:YES];
    }else{
//
//        ZTSingleH5MethodsController * html = [[ZTSingleH5MethodsController alloc] init];
//        NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:APPDeviceToken];
//        if (![urlstring containsString:@"token="]) {
//            NSString *urlStr = @"";
//            if (![urlstring containsString:@"?"]) {
//                urlStr = [NSString stringWithFormat:@"%@?token=%@",urlstring,token];
//            }else{
//                urlStr = [NSString stringWithFormat:@"%@&token=%@",urlstring,token];
//            }
//            urlstring = urlStr;
//        }
//        //    if ([urlstring containsString:@"&deviceId=ios"]) {
//        //        NSString * url = [urlstring stringByReplacingOccurrencesOfString:@"&deviceId=ios" withString:@""];
//        //        urlstring = [NSString stringWithFormat:@"%@&deviceId=ios",url];
//        //    }
//        html.urlString = urlstring;
//        [self.navigationController pushViewController:html animated:YES];
    }
    

    
}

#pragma mark- ------ 纯网址跳转需要单点登录 ------
- (void)openSingleH5MethodsWithParaDic:(NSDictionary *)dict{
    
    ZTLoadZYHTMLViewController * html = [[ZTLoadZYHTMLViewController alloc] init];
    html.hostUrlString = dict[@"ip"];
    html.url = dict[@"url"];
    [self.navigationController pushViewController:html animated:YES];
}

#pragma mark - ------ 跳转 ------
- (void)openH5ModuleMethodsWithParaDic:(NSDictionary *)dict{
    
    NSString *ipString;
    if ([dict.allKeys containsObject:@"ip"]) {
        ipString = dict[@"ip"];
    }
//    if ([[dict objectForKey:@"appCode"] isEqualToString:@"networkCloudDisk"]){//云盘
//        //        [self showHUDOnlyText:@"暂无权限"];
//        //        return;
//        [self showHudInView:self.view hint:@"加载中"];
//        requestService *  req = [requestService new];
//        [req getZyInfoTokenWithSuccess:^(NSString *result) {
//            if (@available(iOS 10.0, *)) {
//                [req getYunLoginWithJwt:result Success:^(NSString *result) {
//                    [self hideHud];
//                    [[requestService new] getYunList];
//                } fail:^(ErrorModel *model) {
//                    [self hideHud];
//                    [self showHUDOnlyText:model.message];
//                }];
//            }else{
//                [self hideHud];
//                [self showHUDOnlyText:@"不支持iOS10系统下使用"];
//            }
//        } fail:^(ErrorModel *model) {
//            [self hideHud];
//            [self showHUDOnlyText:model.message];
//        }];
//        return;
//    }
//    if ([[dict objectForKey:@"appCode"] isEqualToString:@"news"]){//新闻
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
////        html.hostUrlString = @"http://130.120.110.122";
//        html.urlString = [html.hostUrlString stringByAppendingFormat:ZYREDIRECT_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"ybj_meeting"]){//会议
////        之前是meeting
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
//        html.urlString = [ipString stringByAppendingFormat:ZYMEETING_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"collaboration"]){//事务
////        ipString = @"http://211.136.92.2:20080";//移动云
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//
//        html.hostUrlString = ipString;
////        html.hostUrlString = @"http://130.120.110.163";
//        html.urlString = [html.hostUrlString stringByAppendingFormat:ZYSHIWU_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"doc"]){//文档中心
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
////        html.hostUrlString = @"http://130.120.110.163";
//        html.urlString = [html.hostUrlString stringByAppendingFormat:ZYWENDANGZHONGXIN_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"bulletin"]){//公告
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
//        html.urlString = [ipString stringByAppendingFormat:ZYGONGGAO_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"gongwen"]){//公文、正文
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
////        html.hostUrlString = @"http://130.120.110.122";
//        html.urlString = [html.hostUrlString stringByAppendingFormat:ZYZHENGWEN_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"offic"]){//办公
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
//        html.urlString = [ipString stringByAppendingFormat:ZYBANGONG_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"daiban"]){//待办
//        ZTWebViewController * html = [[ZTWebViewController alloc] init];
//        html.hostUrlString = ipString;
//        html.urlString = [ipString stringByAppendingFormat:ZYDAIBAN_URI];
//        html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
//    }
    
//    else if ([[dict objectForKey:@"appCode"] isEqualToString:@"scheduleList"]){//日程列表
//
//        ZScheduleTopViewController *scheduleList = [ZScheduleTopViewController new];
//        [self.navigationController pushViewController:scheduleList animated:YES];
//    }
    
    else if ([[dict objectForKey:@"appCode"] isEqualToString:@"dcqzjw"]){
        ZLoadHTMLViewController * html = [[ZLoadHTMLViewController alloc] init];
        html.type = @"1";
        html.url = [dict objectForKey:@"ip"];//objModel1.appSsoUrl;
        html.title = [dict objectForKey:@"appName"];//objModel1.appName;
        [self presentViewController:html animated:YES completion:nil];
    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"sms"]){//短信
//         ZTSingleH5MethodsController * html = [[ZTSingleH5MethodsController alloc] init];
////                html.hostUrlString = ipString;
////        http://130.120.110.127:8080/#/AppShortMsg?userid=dad953fdc52301fcac7794827cf42212&account=yangmenglu1&device=ios&zhengtong
//        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//        NSString *userId = [userDefaults objectForKey:APPDeviceToken];
//
//        NSString *account = [[ZTUserInfoManage defaultService] getLoginUserAccount];
//        html.urlString = [NSString stringWithFormat:@"%@?userid=%@&account=%@&device=ios&zhengtong",[dict objectForKey:@"ip"],userId,account];
//                html.title = [dict objectForKey:@"appName"];
//        [self.navigationController pushViewController:html animated:YES];
        
    }else if ([[dict objectForKey:@"appCode"] isEqualToString:@"zhyl"]){//智慧养老
//        ZTSingleH5MethodsController * html = [[ZTSingleH5MethodsController alloc] init];
//        NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:APPDeviceToken];
//        NSString *urlStr = [NSString stringWithFormat:@"%@?token=%@",ipString,token];
//        html.urlString = urlStr;
//        [self.navigationController pushViewController:html animated:YES];
    }else{
        if (dict) {
//            ZTSingleH5MethodsController * html = [[ZTSingleH5MethodsController alloc] init];
//            html.urlString = [dict objectForKey:@"ip"];//objModel1.appSsoUrl;
//            html.title = [dict objectForKey:@"appName"];//objModel1.appName;
//            [self.navigationController pushViewController:html animated:YES];
        }
    }
    
}

#pragma mark - ------ 原生界面跳转 ------
- (void)openAppSelfMethods:(NSString *)type{
    
    NSLog(@"原生界面");

}

@end
